(function () {
    'use strict';

    angular
    .module('app')
    .factory('APIConfigService', APIConfigService);

    APIConfigService.$inject = ['$http', '$q', '$timeout', 'CacheFactory', 'ENUM'];

    function APIConfigService($http, $q, $timeout, CacheFactory, ENUM) {

        var service = new APIEndpoint( $http, $q, $timeout, CacheFactory, 'APIConfigService' );

        service.getConfig = function( params ) {
            return this.fetch( '/weixin/weixin/getConfig', params, false, function(res){
                if ( ENUM.ERROR_CODE.OK == res.data.code ) {
                    if (GLOBAL_CONFIG.ENCRYPTED){
                        return res.data;
                    } else {
                        var key = "wenjoying@126.com";
                        var data =  JSON.parse( XXTEA.decryptFromBase64(res.data.data, key) );
                        return data;
                    }
                }
                return null;
            });
        };

        return service;
    }

})();
